package cn.edu.ctbu.demo2.service.impl;


import cn.edu.ctbu.demo2.domain.Score;
import cn.edu.ctbu.demo2.domain.Student;
import cn.edu.ctbu.demo2.domain.User;
import cn.edu.ctbu.demo2.repository.ScoreRepository;
import cn.edu.ctbu.demo2.repository.StudentRepository;
import cn.edu.ctbu.demo2.repository.UserRepository;
import cn.edu.ctbu.demo2.service.ScoreService;
import cn.edu.ctbu.demo2.service.StudentService;
import cn.edu.ctbu.demo2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreimplService implements ScoreService {

    @Autowired
    private ScoreRepository scoreRepository;
    public Score Insert(Score score){
        scoreRepository.save(score);
        return score;
    }
    public Score add(Score score){
        scoreRepository.save(score);
        return score ;
    }

    public Page<Score> findAll(Pageable pageable){
        return scoreRepository.findAll(pageable);
    };

    public Page<Score> findAll(Example<Score> score, Pageable pageable){
        return scoreRepository.findAll(score,pageable);
    }

    public Score getById(Integer id){

        return scoreRepository.findById(id).orElse(null);
    }

    public Score update(Score score){
        scoreRepository.save(score);
        return score;
    }

    public void delete(Integer id){
        Score score=new Score();
        score.setId(id);
        scoreRepository.delete(score);
    }
}
